Algorithms
and
Data
Structures

Spring 2021
course
site
-->

April 19 - shortest path algorithms

... start recording

Questions?

Today I'd like to discuss several "shortest" algorithms on weighted graphs. Your assignment this week is essentially to show that you understand this stuff, by summarizing what's going on here in your own words.

context

Along the way we've seen several different ideas behind these algorithms :

Today's algorithms use two more ideas :

weighted graph

For all of these, we are given a graph G with

Often the weight is the distance along the edge, but it might also be the flow or bandwidth or whatever. Usually the weights are positive.

For all of these algorithms, we will need to be able to find quickly the neighbors any vertex V, and so will need a data structure that is something like

{ Vi : [(Vj, w_ij), ...], ... }

which says that for the i'th vertex Vi, there is a list of the edges which connect Vi to Vj, and the weight w_ij of that edge.

This is the "adjacency list" we have already seen, with the addition of a weight for each edge.

Skienna uses a linked list here; in python we could just use python's lists.

For an "undirected" graph w_ij = w_ji, and each edge shows up twice in that data structure, once as i's connection to j, and once as j's connection to i.

things to understand

The real goal here is get a sense of the ideas that go into algorithms like these, more than these particular ones. There are many variations, and many, many different problems. Some are doable; some are not. Some can only be solved approximately for practical sizes.

You should be paying attention to questions like :

One good way to build your understanding is to work through the algorithm on a tiny problem by hand - that means typing out everything, including the data structures, for enough steps to see what's what. Tedious but helpful.

We'll talk through some of these in class today, depending on how far we get.

We may also try to write some code to solve one of them today and/or Thursday.

minimum spanning tree

shortest path

... I've attached a .pdf of the whiteboard diagram I drew in class.

aside

https://cs.bennington.college /courses /spring2021 /algorithms /notes /shortest path
last modified Mon April 19 2021 11:03 pm

attachments [paper clip]

  last modified size
TXT whiteboard.pdf Mon Apr 19 2021 11:02 pm 481K